package com.MovieManageSystem.controller;
import com.MovieManageSystem.domain.Comment;
import com.MovieManageSystem.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin(origins = "*")
@RequestMapping("/api/comments")
public class CommentController {

    @Autowired
    private CommentService commentService;

    // 提交评论
    @PostMapping
    public ResponseEntity<Comment> submitComment(@RequestBody Comment comment) {
        commentService.submitComment(comment);
        return ResponseEntity.ok(comment);
    }

    // 获取某部电影的所有评论
    @GetMapping("/movie/{vid}")
    public ResponseEntity<List<Comment>> getCommentsByMovieId(@PathVariable Integer vid) {
        List<Comment> comments = commentService.getCommentsByMovieId(vid);
        return ResponseEntity.ok(comments);
    }

    // 获取所有评论
    @GetMapping("/all")
    public ResponseEntity<List<Comment>> getAllComments() {
        List<Comment> comments = commentService.getAllComments();
        return ResponseEntity.ok(comments);
    }
    @GetMapping
    public ResponseEntity<List<Comment>> getCommentList(){
        List<Comment> comments =  commentService.getCommentList();
        return ResponseEntity.ok(comments);
    }

    // 删除评论
    @DeleteMapping("/{cid}")
    public ResponseEntity<Void> deleteComment(@PathVariable Integer cid) {
        commentService.deleteCommentByCid(cid);
        return ResponseEntity.noContent().build();
    }
}
